package com.survey.application.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.survey.application.bean.User;
import com.survey.application.dao.UserDao;
import com.survey.utils.DataUtil;
@Service
public class UserService {
	@Resource(name="userDao")
	private UserDao userDao;
	public void saveUser(User user){
		//密码加密存储
		user.setPassword(DataUtil.md5(user.getPassword()));
		userDao.saveBean(user);
	}
	/**
	 *校验登陆
	 */
	public User checkLogin(User user){
		String hql="from User user where user.account='"+user.getAccount()+"' "
				+ "and user.password='"+DataUtil.md5(user.getPassword())+"'";
		List<User> users=userDao.getBeanByHql(hql);
		return users.size()==0?null:users.get(0);
	}
	/**
	 * ajax 校验
	 * @param account
	 * @return
	 */
	public String checkSameAccount(String account) {
		String hql="from User user where user.account='"+account+"'";
		List<User> users=userDao.getBeanByHql(hql);
		/*if(users.size()==0){
			return false;
		}*/
//		String exist="{\"value\":\""+users.size()+"\"}";
		String exist="{\"value\":\""+users.size()+"\"}";
		return exist;
	}
}

